// This file was decompiled using SASCM.ini published by GTAG (http://gtag.gtagaming.com/opcode-database) on 14.6.2013
{$CLEO .cs}
//-------------MAIN---------------
03A4: name_thread 'HELISFLYBY' 

if
    0AAB:   file_exists "cleo\flybysupports.ini"
then
	// hotkeys
	0AF0: 2@ = get_int_from_ini_file "cleo\flybysupports.ini" section "HOTKEYS" key "AJOM_CALLSUPPORTS1"
	0AF0: 3@ = get_int_from_ini_file "cleo\flybysupports.ini" section "HOTKEYS" key "AJOM_CALLSUPPORTS2"
	
	0AF0: 4@ = get_int_from_ini_file "cleo\flybysupports.ini" section "HOTKEYS" key "AJOM_DISBANDSUPPORTS1"
	0AF0: 5@ = get_int_from_ini_file "cleo\flybysupports.ini" section "HOTKEYS" key "AJOM_DISBANDSUPPORTS2"
	
	0AF0: 7@ = get_int_from_ini_file "cleo\flybysupports.ini" section "HOTKEYS" key "AJOM_SUPPORTSATTACKTARGET1"
	0AF0: 8@ = get_int_from_ini_file "cleo\flybysupports.ini" section "HOTKEYS" key "AJOM_SUPPORTSATTACKTARGET2"
else
	// hotkeys
	2@=9
	3@=187
	
	4@=9
	5@=72
	
	7@=74
	8@=74
end

0001: wait 0 ms 
0247: load_model #RAINDANC 
0247: load_model #SWAT
0247: load_model #ARMY
0247: load_model #MINIGUN 
0247: load_model #rocketla 
0001: wait 0 ms 

const
	searchtargetradius=60.0 // must be a FLOAT
	targetflybyradius=15.0 // must be a FLOAT
	cjradiusheli=20.0 // must be a FLOAT
	huntmodeswitch=31@
	decision=21@
	tempvar=21@
	
	statustextposx1=0.0
	statustextposx2=150.0
	
	// helistartposx=200.0
	// helistartposy=200.0
	// statustextposy=1.0
	
	helistartposx=-200.0
	helistartposy=200.0
	statustextposy=11.0
	
	// helistartposx=-200.0
	// helistartposy=-200.0
	// statustextposy=21.0
end
huntmodeswitch=1
0709: set_decision_maker decision on_event 15 taskID 1000 respect 0.0 hate 0.0 like 0.0 dislike 0.0 in_car 1 on_foot 1
0709: set_decision_maker decision on_event 36 taskID 1000 respect 0.0 hate 0.0 like 0.0 dislike 0.0 in_car 1 on_foot 1     
0709: set_decision_maker decision on_event 15 taskID 1003 respect 0.0 hate 0.0 like 0.0 dislike 0.0 in_car 1 on_foot 1
0709: set_decision_maker decision on_event 36 taskID 1003 respect 0.0 hate 0.0 like 0.0 dislike 0.0 in_car 1 on_foot 1

0ADF: add_dynamic_GXT_entry 'H1DW' text "Helicopter 1: Down"
0ADF: add_dynamic_GXT_entry 'H1HT' text "Helicopter 1: Hunting:"
0ADF: add_dynamic_GXT_entry 'H1SB' text "Helicopter 1: Standby:"

:restart
0001: wait 0 ms 
00D6: if and
0AB0:   key_pressed 2@ 
0AB0:   key_pressed 3@ 
004D: jump_if_false @restart

03A4: name_thread 'startflyby'
0001: wait 0 ms 
04C4: store_coords_to 27@ 28@ 29@ from_actor $PLAYER_ACTOR with_offset helistartposx helistartposy 200.0
00A5: 0@ = create_car #RAINDANC at 27@ 28@ 29@
0825: set_helicopter 0@ instant_rotor_start 
0186: 22@ = create_marker_above_car 0@
0165: set_marker 22@ color_to 1
0129: 1@ = create_actor_pedtype 8 model #ARMY in_car 0@ driverseat 

// 0@				-	chopper 1
// 1@				-	driver 1
// 2@,3@,4@,5@		-	crews 1
// 6@				-	target 1

// 7@				-	chopper 2
// 8@				-	driver 2
// 9@,10@,11@,12@	-	crews 2
// 13@				-	target 2

// 14@				-	chopper 3
// 15@				-	driver 3
// 16@,17@,18@,19@	-	crews 3
// 20@				-	target 3

wait 0 ms // immunes the next lines from getting disabled splash text
03F0: enable_text_draw 0 // disable splashtext
wait 0 ms // immunes the next lines from getting disabled splash text

009A: 16@ = create_actor_pedtype 8 model #ARMY at 0.0 0.0 0.0 
087E: set_actor 16@ weapon_droppable 0
0350: set_actor 16@ maintain_position_when_attacked 1 
060B: set_actor 16@ decision_maker_to decision // offensive state
07DD: set_actor 16@ attack_rate 100 // previously known as temper_to 

009A: 17@ = create_actor_pedtype 8 model #ARMY at 0.0 0.0 0.0 
087E: set_actor 17@ weapon_droppable 0
0350: set_actor 17@ maintain_position_when_attacked 1 
060B: set_actor 17@ decision_maker_to decision // offensive state
07DD: set_actor 17@ attack_rate 100 // previously known as temper_to 

009A: 9@ = create_actor_pedtype 8 model #SWAT at 0.0 0.0 0.0 
087E: set_actor 9@ weapon_droppable 0
0350: set_actor 9@ maintain_position_when_attacked 1 
060B: set_actor 9@ decision_maker_to decision // offensive state
07DD: set_actor 9@ attack_rate 100 // previously known as temper_to 

009A: 10@ = create_actor_pedtype 8 model #SWAT at 0.0 0.0 0.0 
087E: set_actor 10@ weapon_droppable 0
0350: set_actor 10@ maintain_position_when_attacked 1 
060B: set_actor 10@ decision_maker_to decision // offensive state
07DD: set_actor 10@ attack_rate 100 // previously known as temper_to 
	
// position system :
// 0 - means looking forward
// 1 - means looking at left side
// 2 - means looking behind
// 3 - means looking at right side

0464: put_actor 16@ into_turret_on_car 0@ at_car_offset 1.8 0.50 0.0 position 3 shooting_angle_limit 60.0 with_weapon 38
0464: put_actor 17@ into_turret_on_car 0@ at_car_offset -1.8 0.50 0.0 position 1 shooting_angle_limit 60.0 with_weapon 38
0464: put_actor 9@ into_turret_on_car 0@ at_car_offset 3.0 -0.50 0.0 position 3 shooting_angle_limit 45.0 with_weapon 35
0464: put_actor 10@ into_turret_on_car 0@ at_car_offset -3.0 -0.50 0.0 position 1 shooting_angle_limit 45.0 with_weapon 35

:ReferenceChecker
0001: wait 1000 ms

// refresher system
00D6: if and
	8117:  	not player $PLAYER_CHAR wasted
	8118:   not actor $PLAYER_ACTOR dead
004D: jump_if_false @ForceRemover
00D6: if or
	8AB0:   not key_pressed 4@ 
	8AB0:   not key_pressed 5@ 
004D: jump_if_false @ForceRemover
//

// using array:
// 5@	-	the starting local variable
// 27@	-	the offset local variable
///
// 4i 	-	consist into two quantities:
// "4" means number of indexes, in our case we use 0-3 meaning 4 indexes... If you wish to increas the indexes. eg 5@ to 27@. then the this value must be "(5-20)+1"=16
// "i" means the index is an integer value
///
// so if 27@ = 2 then 6@(27@,4i) means:
// 9@ + 2 = 3@
// so if 27@ = 0 then 6@(27@,4i) means:
// 9@ + 0 = 9@

wait 0 ms // immunes the next lines from getting disabled splash text
03F0: enable_text_draw 0 // disable splashtext
wait 0 ms // immunes the next lines from getting disabled splash text

tempvar=0
if and
	0118: actor 16@ dead // right minigun man
	0118: actor 17@ dead // left minigun man
	0118: actor 9@ dead // right rocket launcher man
	0118: actor 10@ dead // left rocket launcher man
then
	045A: draw_text_1number statustextposx1 statustextposy GXT 'H1DW' number -1  // helicopter down
	jump @ForceRemover
else
	if or
		0118: actor 1@ dead // helicopter driver
		0119: car 0@ wrecked
	then
		045A: draw_text_1number statustextposx1 statustextposy GXT 'H1DW' number -1  // helicopter down
		jump @ForceRemover
	else
		if and
			8184: not actor 16@ health >= 1
			8184: not actor 17@ health >= 1
			8184: not actor 9@  health >= 1
			8184: not actor 10@ health >= 1
		then
			045A: draw_text_1number statustextposx1 statustextposy GXT 'H1DW' number -1  // helicopter down
			jump @ForceRemover
		else
			if
				056D: actor 16@ defined
			then
				if and
					8118: not actor 16@ dead
					0A32: actor 16@ on_turret_of_car
					0184: actor 16@ health >= 1
				then
					tempvar+=1
				end
			end
			if
				056D: actor 17@ defined
			then
				if and
					8118: not actor 17@ dead
					0A32: actor 17@ on_turret_of_car
					0184: actor 17@ health >= 1
				then
					tempvar+=1
				end
			end
			if
				056D: actor 9@ defined
			then
				if and
					8118: not actor 9@ dead
					0A32: actor 9@ on_turret_of_car
					0184: actor 9@ health >= 1
				then
					tempvar+=1
				end
			end
			if
				056D: actor 10@ defined
			then
				if and
					8118: not actor 10@ dead
					0A32: actor 10@ on_turret_of_car
					0184: actor 10@ health >= 1
				then
					tempvar+=1
				end
			end
			
			if and
				8A32: not actor 16@ on_turret_of_car
				8A32: not actor 17@ on_turret_of_car
				8A32: not actor 9@ on_turret_of_car
				8A32: not actor 10@ on_turret_of_car
			then
				045A: draw_text_1number statustextposx1 statustextposy GXT 'H1DW' number -1  // helicopter down
				jump @ForceRemover
			end
		end
	end
end

if
	056E:   car 0@ defined
then
	if
		8119:  not car 0@ wrecked
	then
		// if and
		// 	0AB0: key_pressed 74 // J
		// 	huntmodeswitch==0 // hunt mode is off 
		// then
		// 	huntmodeswitch=1 // hunt mode on
		// else
		// 	if and
		// 		0AB0: key_pressed 72 // H
		// 		huntmodeswitch==1 // hunt mode is on
		// 	then
		// 		huntmodeswitch=0 // hunt mode off
		// 		0726: heli 0@ follow_actor $PLAYER_ACTOR follow_car -1 radius cjradiusheli
		// 	else
		 		if and
		 			0AB0: key_pressed 7@ // R
		 			0AB0: key_pressed 8@ // R
		 			00E1:   player 0 pressed_key 6 // aim weapon
		 			huntmodeswitch==1 // hunt mode is on
		 		then
		 			0006: 27@ = -1 
		 			0AD2: 27@ = player $PLAYER_CHAR targeted_actor //IF and SET
		 			00D6: if 
		 				8039:   not  27@ == -1 
		 			then
		 				0085: 6@ = 27@ // (int) // store this actor as helicopter's new target
		 			end
		 		end
		// 	end
		// end
		
		if
			huntmodeswitch==1 // hunt mode is on
		then
			if or
				856D: not actor 6@ defined
				6@==-1
			then
				gosub @helihuntenemies
			else
				if or
					0118: actor 6@ dead
					8104: not actor $PLAYER_ACTOR near_actor 6@ radius searchtargetradius searchtargetradius searchtargetradius sphere 0
				then
					gosub @helihuntenemies
				else
					0726: heli 0@ follow_actor 6@ follow_car -1 radius targetflybyradius
					045A: draw_text_1number statustextposx1 statustextposy GXT 'H1HT' number tempvar  // helicopter hunt
					045A: draw_text_1number statustextposx2 statustextposy GXT 'NUMBER' number tempvar  // helicopter hunt
				end
			end
		end
	end
else
	
	045A: draw_text_1number statustextposx1 statustextposy GXT 'H1DW' number -1  // helicopter down
	jump @ForceRemover
	
end

if
	856E:  not car 0@ defined
then
	jump @ForceRemover
else
	if
		056E:  car 0@ defined
	then
		if
			0119:  car 0@ wrecked
		then
			045A: draw_text_1number statustextposx1 statustextposy GXT 'H1DW' number -1  // helicopter down
			jump @ForceRemover
		end
	end
end
jump @ReferenceChecker

:ForceRemover

0001: wait 0 ms
03F0: enable_text_draw 0 // disable splashtext
0001: wait 0 ms

if 
	056D:  actor 1@ defined
then
	01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
end

if 
	056D:  actor 16@ defined
then
	01C2: remove_references_to_actor 16@ // Like turning an actor into a random pedestrian
end

if 
	056D:  actor 17@ defined
then
	01C2: remove_references_to_actor 17@ // Like turning an actor into a random pedestrian
end

if 
	056D:  actor 9@ defined
then
	01C2: remove_references_to_actor 9@ // Like turning an actor into a random pedestrian
end

if 
	056D:  actor 10@ defined
then
	01C2: remove_references_to_actor 10@ // Like turning an actor into a random pedestrian
end


if
	075C:  marker 22@ enabled
then
	0164: disable_marker 22@
end

if
	056E:   car 0@ defined
then
	01C3: remove_references_to_car 0@
end

6@=-1

0002: jump @restart

:helihuntenemies
if
	056E:   car 0@ defined
then
	if
		8119:  not car 0@ wrecked
	then
		REPEAT
			0001: wait 0 ms // add a delay so that it can be interrupted by other scripts and will not result hang on computer
			00A0: store_actor $PLAYER_ACTOR position_to 27@ 28@ 29@
			0006: 6@ = -1
			0AE1: 6@ = random_actor_near_point 27@ 28@ 29@ in_radius searchtargetradius find_next 1 pass_deads 1 //IF and SET
			if and
				6@ <> -1
				056D:  actor 6@ defined
			then
				089F: get_actor 6@ pedtype_to 27@
				if and
					87D6:  not 6@ == $PLAYER_ACTOR // @ == $ (int)
					86EE:  not actor 6@ in_group $PLAYER_GROUP
					27@ <> 8 // not a grove street family
					8118: not actor 6@ dead
					0184:  actor 6@ health >= 1
				then
					0726: heli 0@ follow_actor 6@ follow_car -1 radius targetflybyradius
					// 0727: set_heli 0@ behavior_to_police_heli_and_follow_actor 6@ follow_car -1 radius targetflybyradius
					
					045A: draw_text_1number statustextposx1 statustextposy GXT 'H1HT' number tempvar  // helicopter hunt
					045A: draw_text_1number statustextposx2 statustextposy GXT 'NUMBER' number tempvar  // helicopter hunt
					
					break
				end
			end
		UNTIL 6@ == -1 // no more peds found
		
		if
			856D: not actor 6@ defined
		then
			0726: heli 0@ follow_actor $PLAYER_ACTOR follow_car -1 radius cjradiusheli
			
			045A: draw_text_1number statustextposx1 statustextposy GXT 'H1SB' number tempvar  // helicopter standby
			045A: draw_text_1number statustextposx2 statustextposy GXT 'NUMBER' number tempvar  // helicopter standby
			
		end
	end
end

return